import os, sys
from google.appengine.ext.webapp import util
import logging

# Delete old django modules
for k in [k for k in sys.modules if k.startswith("django")]:
	del sys.modules[k]

sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + "/pycode"))

os.environ["DJANGO_SETTINGS_MODULE"] = "pycode.settings"
if not os.environ.get("PYTHONPATH"):
	os.environ["PYTHONPATH"] = os.path.abspath(os.path.dirname(__file__) + "/pycode")

import django.core.handlers.wsgi

def main():
	logging.getLogger().setLevel(logging.DEBUG)
	application = django.core.handlers.wsgi.WSGIHandler()
	util.run_wsgi_app(application)

if __name__ == "__main__":
	main()
